<?php
/**
* FILE_NAME : fifth_setp.php   FILE_PATH : D:\xampp\htdocs\id5\web_root\fifth_setp.php
* 处理用户登陆信息
*
* @copyright Copyright www.phpunion.com
* @author slash upsetcn@gmail.com
* @package
* @subpackage
* @version Mon Nov 28 14:11:05 CST 2011
*/
//print_r($_SERVER);exit();
include_once("ThePage.class.php");
$page = new ThePage();
//echo time();exit();
$temp_id = $page->userRequest->get("temp_id");

if(empty($temp_id))
{
	user_log(0,"-3013","error",$_SERVER['SCRIPT_NAME']);
	$temp = $page->userRequest->user_get_cookie('err_url');
	$err_url = empty($temp) ? "404" :urldecode($temp);
	jumpPage($err_url,'',3);
	exit();
}

//身份通用户名
$login_name = isset($_POST['sft']) ? trim($_POST['sft']) : '';
//id5用户名检测
if(empty($login_name))
{
	user_log(0,"-3021","error",$_SERVER['SCRIPT_NAME']);
	alertMsg('-3021');
	exit();
}
$login_pass = isset($_POST['sftpass']) ? trim($_POST['sftpass']) : '';
//id5 用户密码检测
if(empty($login_pass))
{
	user_log(0,"-3022","error",$_SERVER['SCRIPT_NAME']);
	alertMsg('-3022');
	exit();
}

$ver_code = isset($_POST['ver_code']) ? intval($_POST['ver_code']) : 0;
//验证码检测
if(empty($ver_code) ||$page->userRequest->get('VCODE')!=$ver_code)
{
	user_log(0,"-3016","error",$_SERVER['SCRIPT_NAME']);
	alertMsg('-3016');
	exit();
}

$user_arr = @unserialize($page->mc->get(SFT.$temp_id));
if(empty($user_arr))
{
	//mc存储失效
	user_log(0,"-3009","error",$_SERVER['SCRIPT_NAME']);
	goToIndex(-3009);
	exit();
}
$page->set_tpl($user_arr['icpcode']);

//用户登陆动作
$reg = Factory::getItemClass('soapId5');
//print_r($user_arr);
//echo $user_arr['icpcode'];exit();
$result = $reg->loginid5($login_name,$login_pass,$user_arr['icpcode']);
$rtncode = $result['response'][0]['code'];
//print_r($result);exit();
if(empty($result)){
	user_log(0,"-3026","error",$_SERVER['SCRIPT_NAME'],$user_arr['icpcode'],$user_arr['user_id']);
	goToIndex('-3026');
	exit;
}
//验证登陆是否成功
if($rtncode==10){
	$user_id = $user_arr['user_id'];
	//设置回调函数
	$icp_arr = get_icpcode_info($user_arr['icpcode']);
	//登陆成功
	$user_arr['sft'] = intval($result['request'][0]['idtagNo']);
	$user_arr['state'] = 1;
	//将返回信息写入MEMCACHE
	$user_arr['gender'] = trim($result['response'][0]['gender']);
	$user_arr['phoneArea'] = trim($result['response'][0]['phoneArea']);
	$user_arr['mobile'] = trim($result['response'][0]['mobile']);
	$user_arr['astro'] = trim($result['response'][0]['astro']);
	$user_arr['addr'] = trim($result['response'][0]['addr']);
	$user_arr['age'] = trim($result['response'][0]['age']);
	$user_arr['photo'] = trim($result['response'][0]['photo']);
	$user_arr['name'] = trim($result['response'][0]['name']);
	$user_arr['birthday'] = trim($result['response'][0]['birthday']);
	$user_arr['real_name'] = trim($result['response'][0]['name']);
	$user_arr['identity_card'] = trim($result['response'][0]['idcode']);
	$user_arr['user_mob'] = trim($result['response'][0]['mobile']);
	$user_arr['result'] = 1;
	$user_arr['stid'] = intval($login_name);
	//将相关信息放到前台
	//将身份信息返回给对方
	$page->smarty->assign('gender',urlencode($result['response'][0]['gender']));
	//$page->smarty->assign('phoneArea',$result['response'][0]['phoneArea);
	$page->smarty->assign('mobile',$result['response'][0]['mobile']);
	//$page->smarty->assign('astro',$result['response'][0]['astro);
	$page->smarty->assign('addr',urlencode($result['response'][0]['addr']));
	//$page->smarty->assign('age',$result['response'][0]['age);
	//$page->smarty->assign('idcode',$result['response'][0]['idcode);
	$page->smarty->assign('photo',$result['response'][0]['photo']);
	$page->smarty->assign('name',urlencode($result['response'][0]['name']));
	$page->smarty->assign('birthday',$result['response'][0]['birthday']);
	$page->smarty->assign('back_url',$icp_arr['call_back_url']);
	$page->smarty->assign('user_id',$user_id);
	$page->smarty->assign('result',1);
	$user_arr['key_code'] = set_app_key($icp_arr['key'],$user_id,intval($login_name),$icp_arr['icpcode']);
	$page->smarty->assign('key_code',$user_arr['key_code']);
	$page->smarty->assign('stid',intval($login_name));
	//服务器端将数据POST给客户
	$sync = Factory::getItemClass('send_info');
	
	$rs = $sync->put_info($user_arr,$icp_arr['sync_url']);
	//print_r($rs);
	//unset($user_arr['key_code']);
	if($rs){
		$user_arr['send_state'] = 1;
	}else{
		user_log(0,"-3029","error",$_SERVER['SCRIPT_NAME'],$user_arr['icpcode'],$user_arr['user_id']);
		$user_arr['send_state'] = 0;
	}
	$page->mc->set(SFT.$temp_id,serialize($user_arr));
	//成功以后将SESSION和COOKIE释放
	$page->userRequest->free("temp_id");
	
	$page->userRequest->user_set_cookie('err_url','',-3600,$user_arr['icpcode'],$user_arr['user_id']);
	
}else{
	//如果出错
	user_log(0,"-3024","error",$_SERVER['SCRIPT_NAME']);
	alertMsg('-3024');
	exit;
}


//拼接回调url
$url = get_call_back_url($icpcode,$user_arr['user_id'],$result['response'][0]['idtagNo'],$rtncode);
$url = $user_arr['call_back_url']."?".$url;

user_log($temp_id,"suc 5","suc",$_SERVER['SCRIPT_NAME'],$user_arr['icpcode'],$user_arr['user_id'],$user_arr);
$page->smarty->assign('user_name',$user_arr['user_name']);
$page->smarty->assign('url',$url);
$page->smarty->assign('coop_name',$icp_arr['name']);
$page->smarty->display('fifth_step.tpl');
exit();

/*
$login_name = isset($_POST['sft']) ? trim($_POST['sft']) : '';
$login_pass = isset($_POST['sftpass']) ? trim($_POST['sftpass']) : '';



if(empty($login_name) || empty($login_pass) || empty($temp_id)){
	alertMsg('-3001');
}

$ver_code = isset($_POST['ver_code']) ? intval($_POST['ver_code']) : 0;
$v_code = $page->userRequest->get('VCODE');
if($v_code!=$ver_code){
	alertMsg('-3002');
	exit;
}

$reg = Factory::getItemClass('soapId5');
$result = $reg->loginid5($login_name,$login_pass);
print_r($result->response);
$rtncode = $result['response'][0]['code;

//获得用户信息
//取得相关信息
$user_arr = unserialize($page->mc->get(SFT.$temp_id));
$page->smarty->assign('user_name',$user_arr['user_name']);
//取得合作伙伴信息
$icp_arr = get_icpcode_info($icpcode);

$key_code = substr(md5($icp_arr['key'].$user_id.$user_arr['icpcode'].$result->request->idtagNo),0,24);

$url = $user_arr['call_back_url']."?key_code={$key_code}&user_id={$user_arr['user_id']}&stid={$result->request->idtagNo}";
$page->smarty->assign('url',$url);
$page->smarty->assign('coop_name',$icp_arr['name']);

if($rtncode==10){
	$msg = "您已经成功通过身份通的本次认证！";
	$icp_arr['sft'] = intval($result->request->idtagNo);
	$page->mc->set(SFT.$temp_id,serialize($icp_arr));
}else{
	$msg = $result['response'][0]['message;
}

$page->smarty->assign('msg',$msg);
$page->smarty->display('fifth_step.tpl');
*/
?>
